<?php
$my_query = db_query_post_random_in_post_type(3, 'adv', 'rand', $wpdb->prefix.'display', 'display');
query_posts($my_query);
?>
<ul>
<?php
if(have_posts())
{
	while (have_posts())
	{
		the_post();
		$postID = get_the_ID();
		$title = get_the_title($postID);
		$url = get_bloginfo('home');
		$thumbnail = db_get_post_meta($postID,$wpdb->prefix.'thumbnail');
		$perlink = get_post_meta(get_the_ID(),$wpdb->prefix.'thumbnail',true);
		if($perlink)
			$url = $perlink;
		?>
		<li><a href="<?php echo $url;?>" title="<?php echo $title;?>"><img alt="<?php echo $title?>" src="<?php echo $thumbnail;?>" /></a></li>
		<?php 
	}	
} 
else 
{
	echo '<li>No Image.</li>';
}
?>
</ul>                	